<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/01/26
 * Time: 下午 10:35
 */

namespace app\admin\controller;


class Sysmsgabout extends Common
{
    public function index()
    {
        $data = [];
        // 搜索
        $title = input('post.title');
        $data['title'] = $title;
        //页码
        $pageNum = 1;
        if (is_numeric(input('post.pageNum'))) {
            $pageNum = input('post.pageNum');
        }
        $data['pageNum'] = $pageNum;
        //每页数量
        $numPerPage = config('num_per_page');
        $data['numPerPage'] = $numPerPage;
        $Sysabout = new \app\admin\model\Sysmsgabout();
        $list = $Sysabout->getSysList(0,$pageNum,$numPerPage,$title);
        $count = $Sysabout->getSysCount(0,$title);
        $data['list'] = $list;
        $data['count'] = $count;
        return view('',$data);
    }

    public function sysAdd()
    {
        return view('sysadd');
    }

    public function doSysAdd()
    {
        $data = input('post.');
        $data['is_about'] = 0;
        try {
            $sysabout = new \app\admin\model\Sysmsgabout();
            $sysabout->doAddSys($data);
        } catch (Exception $e) {
            return json([
                'statusCode' => 300,
                'message' => $e->getMessage(),
            ]);
        }
        return json([
            'statusCode' => 200,
            'message' => '添加成功',
            'navTabId' => 'SysmsgManage',
            'callbackType' => 'closeCurrent',
        ]);
    }

    public function sysEdit()
    {
        $id = input('get.id');
        $sysab = db("Sysmsg_about")
                ->where("id",$id)
                ->find();
        return view("sysedit",['sysab'=>$sysab]);
    }

    public function doSysEdit()
    {
        $data = input('post.');
        $data['is_about'] = 0;
        try {
            $sysabout = new \app\admin\model\Sysmsgabout();
            $sysabout->doModifySys($data);
        } catch (Exception $e) {
            return json([
                'statusCode' => 300,
                'message' => $e->getMessage(),
            ]);
        }
        return json([
            'statusCode' => 200,
            'message' => '修改成功',
            'navTabId' => 'SysmsgManage',
            'callbackType' => 'closeCurrent',
        ]);
    }

    public function sysDel()
    {
        $id = input("get.id");
        try {
            $sysabout = new \app\admin\model\Sysmsgabout();
            $sysabout->delSys($id);
        } catch (Exception $e) {
            return json([
                'statusCode' => 300,
                'message' => $e->getMessage(),
            ]);
        }
        return json([
            'statusCode' => 200,
            'message' => '删除成功',
            'navTabId' => 'SysmsgManage',
        ]);
    }
}